package com.deng.permission.view{
import com.deng.common.vo.OrganizationVo;
import com.deng.permission.model.PermissionModelLocator;

import flash.events.KeyboardEvent;
import flash.events.MouseEvent;

import mx.controls.Alert;
import mx.controls.CheckBox;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;


	public class UserOrgSelectCB extends CheckBox
	{
		private var pvo:OrganizationVo;
		public function UserOrgSelectCB()
		{							this.addEventListener(FlexEvent.CREATION_COMPLETE,showHandler);			this.addEventListener(FlexEvent.SHOW,showHandler);//本来是2			this.addEventListener(MouseEvent.CLICK,updateEvt);			this.addEventListener(KeyboardEvent.KEY_DOWN,kdEvt);			super();
		}
		private function kdEvt(event:KeyboardEvent)		{			if(event.keyCode == 32)			{				event.stopImmediatePropagation();				return;			}		}		private function updateEvt(event:MouseEvent):void		{			if(this.selected){//之前选中的，后面要删除				var guishuIds:String = PermissionModelLocator.getInstance().tmpUserVo.guishu_id;				if(guishuIds.indexOf(pvo.id+":") == 0)				{					PermissionModelLocator.getInstance().tmpUserVo.guishu_id = guishuIds.replace(pvo.id+":","");				}				else				{					PermissionModelLocator.getInstance().tmpUserVo.guishu_id = guishuIds.replace(":"+pvo.id+":",":");				}			}else{//之前没选中，后面要增加//			Alert.show(this.parent+"   "+this.parent.parent+"   "+this.parent.parent.parent);				if(PermissionModelLocator.getInstance().tmpUserVo.guishu_id == null)				{					PermissionModelLocator.getInstance().tmpUserVo.guishu_id = (pvo.id+":");				}				else				{					PermissionModelLocator.getInstance().tmpUserVo.guishu_id += (pvo.id+":");				}							}	//			Alert.show("....."+PermissionModelLocator.getInstance().tmpUserVo.guishu_id);		}		
		private function flt(evt:FaultEvent):void{
			Alert.show(evt.fault.getStackTrace());
		}		
		private function showHandler(event:FlexEvent):void		{			pvo = this.data as OrganizationVo;			if(PermissionModelLocator.getInstance().tmpUserVo == null)			{				return;			}			var guishuIds:String = PermissionModelLocator.getInstance().tmpUserVo.guishu_id;			if(guishuIds == null || guishuIds.length == 0)			{				this.selected = false;				return;			}			var guishuArr:Array = guishuIds.split(":");			for(var i:int = 0;i<guishuArr.length;i++)			{				var guishuId:String = guishuArr[i] as String;				if(guishuId != "" && guishuId == pvo.id+"")				{					this.selected = true;					return;				}			}			this.selected = false;		}
	}
}